package com.hcy.rabbitbasicmodel.dto;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author huchenying
 * @Description
 * @Date 2022/4/25
 **/
@Data
@NoArgsConstructor
public class MyPage<T> {


    public MyPage(long current,long size,long total){
        this.total = total;
        this.current = current;
        this.size = size;
        updatePageInfo();
    }

    /**
     * 查询数据列表
     */
    protected List<T> records = Collections.emptyList();

    /**
     * 总数
     */
    protected long total;

    /**
     * 每页显示条数，默认 10
     */
    protected long size;

    /**
     * 当前页
     */
    protected long current;

    /**
     * 总共多少页
     */
    protected long totalPage;

    protected List<OrderItem> orders = new ArrayList<>();


    public void updatePageInfo() {
        this.totalPage = total % size == 0 ? total / size : total / size + 1;
    }

}
